package com.wang.controller;

import com.wang.pojo.Pet;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Map;

@Controller
public class ThymeleafController {
    @GetMapping("/thymeleaf1")
    public String thymeleaf1(Model model, Map<String, Object> map, HttpServletRequest request){
        model.addAttribute("a", "你好 thymeleaf");
        map.put("b", "我很好，你想干啥");
        request.setAttribute("c", "查理布朗");
        request.setAttribute("d", "http://www.baidu.com");
        /*
        * thymeleaf已经帮我们配置好了
        * 前缀："classpath:/templates/"
        * 后缀：".html"
        * 因此我们只需要写页面名称即可*/
        return "thymeleaf";
    }
    @GetMapping("/thymeleaf2")
    public String thymeleaf2(){
        return "thymeleaf2";
    }
    //遍历
    @GetMapping("/thymeleaf3")
    public String thymeleaf3(Model model){
        ArrayList<Pet> pets = new ArrayList<>();
        pets.add(new Pet("旺财", 30.33));
        pets.add(new Pet("大黄", 10.33));
        pets.add(new Pet("麦兜", 50.33));
        pets.add(new Pet("仓鼠", 2.33));

        model.addAttribute("pets", pets);

        return "thymeleaf2";
    }
}
